/**
 * Copyright (c) 2013-Now http://jeesite.com All rights reserved.
 */
package com.jeesite.modules.phone.web;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.jeesite.common.config.Global;
import com.jeesite.common.entity.Page;
import com.jeesite.common.web.BaseController;
import com.jeesite.modules.phone.entity.Staff;
import com.jeesite.modules.phone.service.StaffService;

/**
 * 业务员表Controller
 * @author lzw
 * @version 2019-04-03
 */
@Controller
@RequestMapping(value = "${adminPath}/phone/staff")
public class StaffController extends BaseController {

	@Autowired
	private StaffService staffService;
	
	/**
	 * 获取数据
	 */
	@ModelAttribute
	public Staff get(Long id, boolean isNewRecord) {
		return staffService.get(id+"", isNewRecord);
	}
	
	/**
	 * 查询列表
	 */
	@RequiresPermissions("phone:staff:view")
	@RequestMapping(value = {"list", ""})
	public String list(Staff staff, Model model) {
		model.addAttribute("staff", staff);
		return "modules/phone/staffList";
	}
	
	/**
	 * 查询列表数据
	 */
	@RequiresPermissions("phone:staff:view")
	@RequestMapping(value = "listData")
	@ResponseBody
	public Page<Staff> listData(Staff staff, HttpServletRequest request, HttpServletResponse response) {
		Page<Staff> page = staffService.findPage(new Page<Staff>(request, response), staff); 
		return page;
	}

	/**
	 * 查看编辑表单
	 */
	@RequiresPermissions("phone:staff:view")
	@RequestMapping(value = "form")
	public String form(Staff staff, Model model) {
		model.addAttribute("staff", staff);
		return "modules/phone/staffForm";
	}

	/**
	 * 保存业务员表
	 */
	@RequiresPermissions("phone:staff:edit")
	@PostMapping(value = "save")
	@ResponseBody
	public String save(@Validated Staff staff) {
		staffService.save(staff);
		return renderResult(Global.TRUE, "保存业务员表成功！");
	}
	
	/**
	 * 删除业务员表
	 */
	@RequiresPermissions("phone:staff:edit")
	@RequestMapping(value = "delete")
	@ResponseBody
	public String delete(Staff staff) {
		staffService.delete(staff);
		return renderResult(Global.TRUE, "删除业务员表成功！");
	}
	
}